<template>
	<view class="box">

		<view class="">
			<u-navbar :title="tit" :fixed="true" :placeholder="true" :safeAreaInsetTop="true" :autoBack="false"
				leftIconColor="#666" titleStyle="color:#333" bgColor="transparent"  @leftClick="leftClick"></u-navbar>
			<image class="indexbg"
				src="https://images.fudiemall.com/storage/default/20250411/BG77ff634c5c493fbb0cb752c7b44d86c703900c11.png"
				mode="aspectFill"></image>
		</view>
		<view class="wrap_top">
			<view class="search">
				<image src="https://images.fudiemall.com/storage/default/20250415/iconsearchbaa85356c0921b0496a3d8ee4c330a6e719900e1.png" mode="aspectFill"></image>
				<input type="text" v-model.trim="word" placeholder="请输入成员" @confirm="sub" />
			</view>
		</view>
		<view class="main">
			<checkbox-group @change="checkboxChangeAll">
				<view class="item" v-for="item in merberlist" :key="item.id">
					<image :src="item.avatar" mode="aspectFill" @click="gomore(item)"></image>
					<text @click="gomore(item)">{{item.nickname}}</text>
					<view class="tag" v-if="item.is_admin==1">
						群主
					</view>
					<view class="tag" v-if="item.is_admin==2">
						管理员
					</view>
					<checkbox v-if="isshow" borderColor="#333" activeBorderColor="#FFC300" class="checkitem"
						activeBackgroundColor="#FFC300" backgroundColor="#f2f2f2" :checked="false	"
						:value="item.user_id.toString()"></checkbox>
				</view>
			</checkbox-group>
		</view>
		<noDatas :xxxList="merberlist" :status="status"></noDatas>
		
		<view class="empty3">
			
		</view>
		<view class="empty3">
			
		</view>
		<view class="btn" v-if="is_admin!=0" @click="right">
			{{righttxt}}
		</view>
		
		<view style="width: 750rpx;height: 88rpx;">

		</view>
	</view>
</template>

<script>
	import {
		memberDetails,
		groupDetails,
		removeGroupMember
	} from "../../api/hx.js"
	import {
		myuser
	} from "../../api/user.js"
	export default {
		data() {
			return {
				selectedIds: [],
				isshow: false,
				righttxt: "",
				word: "",
				page: 1,
				size: 20,
				status: 'loadmore', //加载前值为loadmore，加载中为loading，没有数据为nomore
				merberlist: [],
				groupid: "",
				tit: "",
				groupinfo: "",
				is_admin: "",
				user: {}
			}
		},
		onLoad(option) {
			this.groupid = option.id
			this.getlist()
			this.groupdetail()
			
		},
		
		onShow() {
			this.groupdetail()
			this.getuser()
		},
		methods: {
			remove() {
				removeGroupMember({
					hx_group_id: this.groupid,
					user_ids: this.selectedIds.join(',')
				}).then(res => {
					if (res.code == 1) {
						this.isshow = false
						this.page=1
						this.getlist()
						this.groupdetail()
						this.selectedIds = []
						this.righttxt = "管理成员"
					}
					uni.$u.toast(res.msg)

				})
			},
			getuser() {
				myuser().then(res => {
					this.user = res.data
				})
			},
			gomore(item) {
				if (this.is_admin != 0 && this.user.id != item.user_id) {

					uni.setStorageSync("groupitem", item)
					uni.navigateTo({
						url: "/pageDao/groupchat/more?id=" + this.groupid
					})

				}
			},
			leftClick() {
				//获取页面栈的长度
				const canNavBack = getCurrentPages()
				console.log(canNavBack.length);
				// 判断是否刷新了浏览器，刷新了浏览器，页面栈只有当前一个
				if (canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: '/pages/index/cloudCatIndex'
					})
				}
			},
			sub() {
				this.page = 1,
					this.getlist()
			},
			groupdetail() {
				groupDetails({
					hx_group_id: this.groupid
				}).then(res => {
					if (res.code == 1) {
						this.groupinfo = res.data
						this.is_admin = res.data.group_user_one.is_admin
						if (this.is_admin != 0) {

							this.righttxt = "管理成员"
						}
						this.tit = `${this.groupinfo.name}(${this.groupinfo.member_number}人)`
						// console.log("群详情", res)
					} else {
						uni.$u.toast(res.msg)
					}

				})
			},
			getlist() {
				memberDetails({
					hx_group_id: this.groupid,
					search_name: this.word,
					page: this.page,
					page_size:20
				}).then(res => {
					if (res.code == 1) {
						let list = res.data.data;
						this.merberlist = this.page == 1 ? list : this.merberlist.concat(list);
						console.log(this.merberlist);
						if (list.length < this.size) this.status = 'nomore';
						else this.status = 'loading';
					}
				})
			},
			leftClick() {
				//获取页面栈的长度
				const canNavBack = getCurrentPages()
				console.log(canNavBack.length);
				// 判断是否刷新了浏览器，刷新了浏览器，页面栈只有当前一个
				if (canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: '/pages/index/cloudCatIndex'
					})
				}
			},
			right() {
				this.isshow = true
				this.righttxt = "删除成员"
				if (this.selectedIds.length != 0) {
					this.remove()


				}
			},
			checkboxChangeAll(e) {
				this.selectedIds = e.detail.value;
				console.log(this.selectedIds)
			},
		},
		onReachBottom() {
			if (this.status != 'nomore') {
				this.page = this.page + 1
				this.getlist()
			}

		}
	}
</script>
<style>
	page {
		background-color: #f7f7f7;
	}
</style>
<style lang="scss">
	.box {
		width: 750rpx;

	}

	.btn{
		width: 696rpx;
		height: 80rpx;
		background: linear-gradient( 270deg, #FA2222 2%, #FFC400 98%);
		border-radius: 190rpx 190rpx 190rpx 190rpx;
		font-weight: 500;
		font-size: 36rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 80rpx;
		position: fixed;
		bottom: 50rpx;
		left: 50%;
		transform: translateX(-50%);
	}
	/deep/.u-navbar__content__title {
		width: 400rpx;
		font-size: 28rpx !important;
	}

	/deep/ .u-navbar__content__right__text {
		color: #FF1616;
	}

	.wrap_top {
		width: 750rpx;
	}

	/deep/.u-navbar__content {
		background: transparent;
	}

	.indexbg {
		position: absolute;
		top: 0;
		left: 0;
		width: 750rpx;
		height: 460rpx;

	}

	.search {
		width: 690rpx;
		height: 72rpx;
		background: #F2F2F2;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		margin: 30rpx auto;
		position: relative;

		>image {
			width: 32rpx;
			height: 30rpx;
			position: absolute;
			top: 22rpx;
			left: 34rpx;

		}

		>input {
			width: 620rpx;
			padding-left: 70rpx;
			height: 72rpx;
			font-weight: 400;
			font-size: 28rpx;
			color: #333333;
		}
	}

	.main {
		width: 750rpx;

	}

	.item {
		width: 690rpx;
		margin: 0 auto;
		margin-top: 24rpx;
		display: flex;
		align-items: center;
		position: relative;

		>image {
			width: 84rpx;
			height: 84rpx;
			border-radius: 50%;
		}

		>text {
			font-weight: 400;
			font-size: 30rpx;
			color: #333333;
			margin-left: 15rpx;
			max-width: 350rpx;
			white-space: nowrap;
			/* 防止文本换行 */
			overflow: hidden;
			/* 隐藏溢出的文本 */
			text-overflow: ellipsis;
			/* 当文本溢出时显示省略号 */
		}

		.tag {
			padding: 5rpx 10rpx 5rpx 10rpx;
			background: #FFC300;
			border-radius: 4rpx 4rpx 4rpx 4rpx;
			opacity: 0.5;
			font-size: 20rpx;
			color: #fff;
			text-align: center;
			margin-left: 20rpx;
		}

		/deep/.uni-checkbox-input {
			width: 30rpx;
			height: 30rpx;
			position: absolute;
			right: 40rpx;
			border-radius: 50%;
		}
		/* #ifdef MP-WEIXIN */
		
			.checkitem{
				width: 30rpx;
				height: 30rpx;
				position: absolute;
				right: 40rpx;
				border-radius: 50%;
				
			}
		/* #endif */
	}
</style>